home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.net.InetAddress;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.util.StringTokenizer;
- import java.util.Vector;
-
- public class FtpClient {
- String host;
- // $FF: renamed from: s java.net.Socket
- Socket field_0;
- boolean Connected = false;
- boolean LoggedIn = false;
- PrintStream ftpout;
- DataInputStream ftpin;
- FtpErrors errs;
- // $FF: renamed from: v java.util.Vector
- Vector field_1;
- Vector files;
- Vector dirs;
- private boolean dataRead = false;
- public static final int ASCII = 0;
- public static final int BINARY = 1;
- private int xferMode = 1;
- private boolean modeChange = true;
-
- public FtpClient(String var1) throws IOException {
- this.host = var1;
- this.Connected = true;
- this.errs = new FtpErrors();
-
- try {
- this.field_0 = new Socket(var1, 21);
- } catch (UnknownHostException var6) {
- this.Connected = false;
- }
-
- this.ftpout = new PrintStream(this.field_0.getOutputStream());
- this.ftpin = new DataInputStream(this.field_0.getInputStream());
- String var2 = this.ftpin.readLine();
-
- int var3;
- try {
- var3 = Integer.parseInt(var2.substring(0, 3));
- } catch (NumberFormatException var4) {
- var3 = -1;
- } catch (StringIndexOutOfBoundsException var5) {
- var3 = -1;
- }
-
- if (var3 == 220) {
- var2 = this.ftpin.readLine();
- } else {
- throw new IOException("Connect");
- }
- }
-
- public void setXferMode(int var1) {
- if (var1 != this.xferMode && (var1 == 0 || var1 == 1)) {
- this.xferMode = var1;
- this.modeChange = true;
- }
-
- }
-
- public int getXferMode() {
- return this.xferMode;
- }
-
- public void login(String var1, String var2) throws FtpLoginException {
- if (var1 == null) {
- throw new FtpLoginException("Login cannot be null");
- } else {
- try {
- int var3;
- if ((var3 = this.doCmd("USER " + var1 + "\n")) != 331) {
- throw new FtpLoginException(this.getError(var3));
- }
-
- if ((var3 = this.doCmd("PASS " + var2 + "\n")) != 230) {
- throw new FtpLoginException(this.getError(var3));
- }
- } catch (IOException var5) {
- throw new FtpLoginException(((Throwable)var5).getMessage());
- }
-
- this.LoggedIn = true;
- }
- }
-
- public boolean loggedIn() {
- return this.LoggedIn;
- }
-
- public DataInputStream getFile(String var1) throws IOException {
- if (this.modeChange) {
- int var3;
- if (this.xferMode == 0) {
- var3 = this.doCmd("TYPE A\n");
- } else {
- var3 = this.doCmd("TYPE I\n");
- }
-
- if (var3 != 200) {
- throw new IOException("Couldn't change xfer mode");
- }
-
- this.modeChange = false;
- }
-
- Socket var2 = this.doIOCmd("RETR " + var1 + "\n");
- String var4 = this.ftpin.readLine();
- return new DataInputStream(var2.getInputStream());
- }
-
- public Vector getFileList() throws IOException {
- boolean var4 = false;
- if (!this.dataRead) {
- this.field_1 = new Vector(100);
- this.files = new Vector(100);
- this.dirs = new Vector(100);
- Socket var1 = this.doIOCmd("LIST -aF\n");
- DataInputStream var2 = new DataInputStream(var1.getInputStream());
- var4 = false;
- if (var1 == null) {
- throw new IOException("Socket creation failed");
- }
-
- while(!var4) {
- String var3 = var2.readLine();
- if (var3 == null) {
- var4 = true;
- } else {
- this.field_1.addElement(var3);
- }
- }
-
- String var7 = this.ftpin.readLine();
- var1.close();
- }
-
- for(int var6 = 1; var6 < this.field_1.size(); ++var6) {
- String var5 = (String)this.field_1.elementAt(var6);
- if (var5.charAt(var5.length() - 1) == '/') {
- this.dirs.addElement(this.getDirName((String)this.field_1.elementAt(var6)));
- } else {
- this.files.addElement(this.getFileName((String)this.field_1.elementAt(var6)));
- }
- }
-
- this.dataRead = true;
- return this.files;
- }
-
- public Vector getDirList() throws IOException {
- if (!this.dataRead) {
- Vector var1 = this.getFileList();
- }
-
- return this.dirs;
- }
-
- private Socket doIOCmd(String var1) throws IOException {
- InetAddress var4 = InetAddress.getLocalHost();
- byte[] var5 = var4.getAddress();
- String var6 = "PORT ";
- ServerSocket var3 = new ServerSocket(0);
-
- for(int var8 = 0; var8 < var5.length; ++var8) {
- var6 = var6 + (var5[var8] & 255) + ",";
- }
-
- var6 = var6 + (var3.getLocalPort() >>> 8 & 255) + "," + (var3.getLocalPort() & 255);
- int var7 = this.doCmd(var6 + "\n");
- if (var7 != 200 && var7 != 226 && var7 != 230) {
- throw new IOException(this.getError(var7));
- } else {
- var7 = this.doCmd(var1);
- if (var7 != 125 && var7 != 150 && var7 != 200) {
- throw new IOException(this.getError(var7));
- } else {
- Socket var2 = var3.accept();
- var3.close();
- return var2;
- }
- }
- }
-
- public void chdir(String var1) throws IOException {
- this.dataRead = false;
- int var2 = this.doCmd("CWD " + var1 + "\n");
- if (var2 != 250 && var2 != 200) {
- this.debug("Return code is: " + var2);
- throw new IOException("Couldn't cd to: " + var1);
- }
- }
-
- private int doCmd(String var1) throws IOException {
- byte[] var2 = new byte[3];
- this.ftpout.print(var1);
- this.ftpin.read(var2);
- this.ftpin.readLine();
- String var4 = new String(var2, 0);
-
- int var3;
- try {
- var3 = Integer.parseInt(var4.substring(0, 3));
- } catch (NumberFormatException var5) {
- var3 = -1;
- } catch (StringIndexOutOfBoundsException var6) {
- var3 = -1;
- }
-
- return var3;
- }
-
- public String getDirName(String var1) {
- String var2 = null;
-
- for(StringTokenizer var4 = new StringTokenizer(var1); var4.hasMoreElements(); var2 = var4.nextToken()) {
- }
-
- String var3 = var2.substring(0, var2.length() - 1);
- return var3;
- }
-
- public String getFileName(String var1) {
- String var2 = null;
-
- for(StringTokenizer var3 = new StringTokenizer(var1); var3.hasMoreElements(); var2 = var3.nextToken()) {
- }
-
- char var4 = var2.charAt(var2.length() - 1);
- return var4 != '*' && var4 != '@' && var4 != '=' ? var2 : var2.substring(0, var2.length() - 1);
- }
-
- public String getError(int var1) {
- return this.errs.getError(var1);
- }
-
- public void closeHard() {
- try {
- this.ftpin.close();
- this.ftpout.close();
- } catch (IOException var1) {
- }
-
- this.LoggedIn = false;
- this.dataRead = false;
- }
-
- public void quit() throws IOException {
- this.doCmd("QUIT\n");
- this.ftpin.close();
- this.ftpout.close();
- }
-
- private void debug(String var1) {
- }
- }
-